cmake_minimum_required(VERSION 3.10)
project(siyuan CXX)

set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} "${CMAKE_SOURCE_DIR}/cmake")

message("   Trilinos_DIR = $ENV{Trilinos_DIR}")
set(CMAKE_PREFIX_PATH $ENV{Trilinos_DIR} ${CMAKE_PREFIX_PATH})
find_package(Trilinos NO_MODULE NO_CMAKE_ENVIRONMENT_PATH NO_SYSTEM_ENVIRONMENT_PATH REQUIRED)
include_directories(SYSTEM ${Trilinos_INCLUDE_DIRS})
include_directories(SYSTEM ${Trilinos_TPL_INCLUDE_DIRS})

MESSAGE("\nFound Trilinos!  Here are the details: ")
MESSAGE("-- Trilinos_DIR = ${Trilinos_DIR}")
MESSAGE("-- Trilinos_VERSION = ${Trilinos_VERSION}")
MESSAGE("-- Trilinos_GIT_COMMIT_ID = ${Trilinos_GIT_COMMIT_ID}")
MESSAGE("-- Trilinos_BIN_DIRS = ${Trilinos_BIN_DIRS}")
MESSAGE("-- Trilinos_TPL_LIST = ${Trilinos_TPL_LIST}")
MESSAGE("-- Trilinos_LIBRARY_DIRS = ${Trilinos_LIBRARY_DIRS}")
MESSAGE("-- Trilinos_INCLUDE_DIRS = ${Trilinos_INCLUDE_DIRS}")
MESSAGE("-- Trilinos_TPL_LIBRARY_DIRS = ${Trilinos_TPL_LIBRARY_DIRS}")
MESSAGE("-- Trilinos_BUILD_SHARED_LIBS = ${Trilinos_BUILD_SHARED_LIBS}")
MESSAGE("-- Trilinos_CXX_COMPILER_FLAGS = ${Trilinos_CXX_COMPILER_FLAGS}")
MESSAGE("End of Trilinos details\n")

message("Setting and checking of compilers:")
set(CMAKE_CXX_COMPILER ${Trilinos_CXX_COMPILER})
set(CMAKE_C_COMPILER ${Trilinos_C_COMPILER})
set(CMAKE_Fortran_COMPILER ${Trilinos_Fortran_COMPILER})

message("-- CMAKE_SYSTEM_NAME = ${CMAKE_SYSTEM_NAME}")
message("-- CMAKE_CXX_COMPILER_ID = ${CMAKE_CXX_COMPILER_ID}")

set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${Trilinos_CXX_COMPILER_FLAGS} ${EXTRA_CXX_FLAGS}")
message("-- CMAKE_CXX_FLAGS = ${CMAKE_CXX_FLAGS}")

file(GLOB_RECURSE SOURCE src/*.cpp)
file(GLOB_RECURSE HEADER "${CMAKE_SOURCE_DIR}/src" *.hpp)
SET(HEADER_DIR "")
FOREACH(file_path ${HEADER})
    GET_FILENAME_COMPONENT(dir_path ${file_path} PATH)
    SET(HEADER_DIR ${HEADER_DIR} ${dir_path})
ENDFOREACH()
LIST(REMOVE_DUPLICATES HEADER_DIR)
include_directories(${HEADER_DIR})
message(STATUS "FOUND HEADER:${HEADER_DIR}")

include_directories(${CMAKE_SOURCE_DIR}/include)
include_directories(${CMAKE_BINARY_DIR}/include)
add_library(syfem ${SOURCE} ${HEADER})
target_link_libraries(syfem PUBLIC ${Trilinos_LIBRARIES})

message("TeuchosParameterList_LIBRARIES = '${TeuchosParameterList_LIBRARIES}'")
message("TeuchosParameterList_INCLUDE_DIRS = '${TeuchosParameterList_INCLUDE_DIRS}'")
message("TeuchosParameterList_TPL_INCLUDE_DIRS = '${TeuchosParameterList_TPL_INCLUDE_DIRS}'")
add_executable(xml2yaml src/utilities/xml2yaml.cpp)
add_executable(yaml2xml src/utilities/yaml2xml.cpp)
target_link_libraries(xml2yaml PUBLIC ${TeuchosParameterList_LIBRARIES})
target_link_libraries(yaml2xml PUBLIC ${TeuchosParameterList_LIBRARIES})
target_include_directories(yaml2xml SYSTEM PUBLIC
  "${TeuchosParameterList_INCLUDE_DIRS};${TeuchosParameterList_TPL_INCLUDE_DIRS}")
target_include_directories(xml2yaml SYSTEM PUBLIC
  "${TeuchosParameterList_INCLUDE_DIRS};${TeuchosParameterList_TPL_INCLUDE_DIRS}")

add_executable(siyuan src/main.cpp)
target_include_directories(syfem PUBLIC ${PROJECT_SOURCE_DIR}/include)
target_include_directories(syfem PUBLIC ${PROJECT_SOURCE_DIR}/src)
target_include_directories(syfem PUBLIC ${Trilinos_INCLUDE_DIRS})
target_link_libraries(siyuan PUBLIC syfem ${Trilinos_LIBRARIES} ${MPI_LIBRARIES} ${CUDA_LIBRARIES})

###############################################################################
# Tests
###############################################################################
enable_testing()
add_subdirectory(tests)
